package com.qckj.quartz.service.impl;

import com.qckj.amz.dao.ConfigMarketplaceDao;
import com.qckj.amz.dao.ProductAmzUploadTaskDao;
import com.qckj.amz.dao.ShopAuthDao;
import com.qckj.amz.domain.ProductAmzUploadTask;
import com.qckj.amz.service.impl.ProductAmzUploadTaskServiceImpl;
import com.qckj.amz.utils.constants.QckjConstants;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.tool_qckj.spring.RowMapperUtils;
import com.qckj.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

/**
 * @author luchuan
 * @version v1.0
 * @date 2022/11/28 0028
 **/

@Service
public class UploadFeedsReportServiceImpl {

    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private ConfigMarketplaceDao configMarketplaceDao;
    @Autowired
    private ShopAuthDao shopAuthDao;
    @Autowired
    private ProductAmzUploadTaskDao productAmzUploadTaskDao;
    @Autowired
    private ISysConfigService configService;
    @Autowired
    private ProductAmzUploadTaskServiceImpl productAmzUploadTaskService;


    /**
     * 获取上传报告
     * @return
     */
    public AjaxResult getUploadFeedsReport() {
        //在实现类中获取ProductAmzUploadTask任务数据
        Date date = new Date();
        String sql = "select * from t_product_amz_upload_task t where t.task_status=? and t.upload_time<= ? ";
        List<ProductAmzUploadTask> productAmzUploadTaskList = jdbcTemplate.query(sql, RowMapperUtils.getRowMapper(ProductAmzUploadTask.class), new Object[]{QckjConstants.QC_FEED_STATUS2, date});
        if (productAmzUploadTaskList ==null || productAmzUploadTaskList.isEmpty()){
            System.out.println("执行产品上传executeUploadFeeds---共执行数据【0】个");
            return AjaxResult.success();
        }

        //执行获取上传报告
        AjaxResult res = productAmzUploadTaskService.executeGetUploadFeedsReport(productAmzUploadTaskList);
        // 定时任务执行，无需返回详细结果，已在数据库中记录详细结果与异常
        return res;
    }

}
